﻿using System.Windows;
using System.Windows.Input;
using DBAccessLibrary.Model;
using DevControlLibrary.Common;
using DevExpress.Xpf.Core;
using QueryResource.Common;

namespace DevControlLibrary.UI.Comparsion
{
    /// <summary>
    /// DataComparsionConnection.xaml 的交互逻辑
    /// </summary>
    public partial class DataComparsionConnection : DXWindow
    {
        public DataComparsionConnection()
        {
            InitializeComponent();
            this.dbSourceConnection.CreateCombox();
            this.dbTargerConnection.CreateCombox();
            XmlHelper.Instance.SetTheme(this);
        }

        public ConnectionModel DataSource { get; set; }
        public ConnectionModel TargetSource { get; set; }

        #region event
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            var targer = this.dbTargerConnection.SubmitAction();
            var source = this.dbSourceConnection.SubmitAction();
            if (!targer.Connection(true))
            {
                MessageBoxHelper.Show("源数据 参数错误，无法连接。");
                return;
            }
            if (!source.Connection(true))
            {
                MessageBoxHelper.Show("目标数据 参数错误，无法连接。");
                return;
            }
            DataSource = source.DataSource;
            TargetSource = targer.DataSource;
            this.DialogResult = true;
        }

        private void btnCanel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.dbTargerConnection.SetData(this.dbSourceConnection.SubmitAction().DataSource);
        }

        private void DXWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            { btnOK_Click(null, null); }
            else if (e.Key == Key.Escape)
            { btnCanel_Click(null, null); }
        }
        #endregion

    }
}
